﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using stackFluent.Domain;

namespace stackFluent.EF {
    public class EFContextInitializer : DropCreateDatabaseIfModelChanges<EFContext> {
        protected override void Seed(EFContext context) {

            User user1 = new User { Email = "zicjin@gmail.com", Password = "123456", Name = "Cheney Jin", Links = "zicjin.wordpress.com" };
            context.Users.Add(user1);
            context.SaveChanges();

            User user2 = new User { Email = "jzcnnn@163.com", Password = "123456", Name = "jzcnnn", Links = "www.163.com" };
            context.Users.Add(user2);
            context.SaveChanges();

            var cates = new List<Category>
            {
                new Category { Name = "data" },
                new Category { Name = ".net-web" },
                new Category { Name = "tutorial" },
                new Category { Name = "common" },
                new Category { Name = "implement" }
            };
            cates.ForEach(d => context.Categories.Add(d));
            context.SaveChanges();

            var techcodes = new List<Tech> {
                new Tech { Name = "Entity-Framework", HomePage = "msdn.microsoft.com/zh-cn/library/bb399572.aspx", CategoryId = 1 }
            };
            techcodes.ForEach(d => context.Techs.Add(d));
            context.SaveChanges();

            var userfavnodes = new List<RelaUserTech>
            {
                new RelaUserTech { UserId = 1, TechId = 1, AbilityByOwnId = 0, ApplicationValue = 2, CommunityValue = 2, QualityValue = 3 }
            };
            userfavnodes.ForEach(d => context.RelaUserTechs.Add(d));
            context.SaveChanges();

            var resourcesites = new List<Site> {
                new Site { Name = "w3schools", HomePage = "www.w3schools.com/cn" },
                new Site { Name = "iteye", HomePage = "iteye.com" },
                new Site { Name = "nuget", HomePage = "nuget.org/" }
            };
            resourcesites.ForEach(s => context.Sites.Add(s));
            context.SaveChanges();

            var tags = new List<Tag>
            {
                new Tag { Name = "orm" },
                new Tag { Name = "sql" },
                new Tag { Name = "csharp" },
                new Tag { Name = "html" },
                new Tag { Name = "javascript" },
            };
            tags.ForEach(d => context.Tags.Add(d));
            context.SaveChanges();

            var resource = new List<Question>
            {
                new Question { Title = "library from msdn", Html = "msdn.microsoft.com/en-us/library/hh289362(v=VS.103).aspx", Grade = 2, TechId = 1, UserId = 1 },
                new Question { Title = "NUnit new version", Html = "nuget.org/packages/NUnit", Grade = 2, TechId = 1, UserId = 1 }
            };
            resource.ForEach(d => context.Questions.Add(d));
            context.SaveChanges();

            var questions = new List<Resource>
            {
                new Resource { Title = "what's up??", Html = "fuck you somethings", TechId = 1, UserId = 1 },
                new Resource { Title = "where is this", Html = "rtrtrtrt", TechId = 1, UserId = 1, DeviceId = (int)eDevice.PC }
            };
            questions.ForEach(d => context.Resources.Add(d));
            context.SaveChanges();

            var chats = new List<Chat>
            {
                new Chat { Html = "hello world!!", NodeId = 1,NodeTypeId=1, UserId = 1 },
                new Chat { Html = "hello to chat!!", NodeId = 1,NodeTypeId=0, UserId = 1 },
                new Chat { Html = "hello EntityFramework!!", NodeId = 1,NodeTypeId=0, UserId = 2 },
            };
            chats.ForEach(d => context.Chats.Add(d));
            context.SaveChanges();
        }
    }
}
